package org.zfes.snowier.cloud.zbss.loan.loan.controller;

import java.util.Map;
import java.util.Optional;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.zfes.snowier.core.data.DataSet;
import org.zfes.snowier.web.controller.BaseController;
import org.zfes.snowier.cloud.zbss.loan.loan.model.LoanUserInfo;
import org.zfes.snowier.cloud.zbss.loan.loan.service.ILoanUserInfoService;
@Controller 
@RequestMapping("/loan/loanUserInfo")
public class LoanUserInfoController extends BaseController {

	
	@Autowired
	private ILoanUserInfoService loanUserInfoService;
	
	//@RequiresPermissions(value="loanUserInfo:loadLoanUserInfoDataSet",desc="用户信息列表")
    @RequestMapping(value="/loadLoanUserInfoDataSet", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object loadLoanUserInfoDataSet(@RequestParam Map<String,Object> params){
	    DataSet dataSet=  loanUserInfoService.loadLoanUserInfoDataSet(params);
	    return ajaxQuery("dataSet", dataSet);
    }
	
	//@RequiresPermissions(value="loanUserInfo:createLoanUserInfo",desc="用户信息添加")
    @RequestMapping(value="/createLoanUserInfo", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public  @ResponseBody Object createLoanUserInfo(LoanUserInfo loanUserInfo){
		Long id = loanUserInfoService.createLoanUserInfo(loanUserInfo);
		return ajaxQuery("userId", id);
    }
	
	//@RequiresPermissions(value="loanUserInfo:loadLoanUserInfo",desc="用户信息加载")
    @RequestMapping(value="/loadLoanUserInfo", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object loadLoanUserInfo(Long id){
		Optional<LoanUserInfo> ops = loanUserInfoService.loadLoanUserInfoById(id);
		return ops;
    }
	
	//@RequiresPermissions(value="loanUserInfo:updateLoanUserInfo",desc="用户信息更新")
    @RequestMapping(value="/updateLoanUserInfo", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object updateLoanUserInfo(LoanUserInfo loanUserInfo){
		loanUserInfoService.updateLoanUserInfo(loanUserInfo);
		return ajaxDoneSuccess("数据操作成功 ");
    }
	
	//@RequiresPermissions(value="loanUserInfo:deletLoanUserInfo",desc="用户信息删除")
    @RequestMapping(value="/deleteLoanUserInfo", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object deleteLoanUserInfo(Long id){
		loanUserInfoService.deleteLoanUserInfo(id);
		return ajaxDoneSuccess("数据操作成功 ");
    }

	@RequestMapping(value="/queryUserForOpenId", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public @ResponseBody  Object queryUserForOpenId(String openId){
		Optional<LoanUserInfo> ops = loanUserInfoService.queryUserForOpenId(openId);
		return ajaxQuery("loanUserInfo",ops);
	}


	@RequestMapping(value="/setLoanUserInfoStatus", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public @ResponseBody  Object setLoanUserInfoStatus(Long id, Byte status){
		loanUserInfoService.setLoanUserInfoStatus(id,status);
		return ajaxDoneSuccess("数据操作成功 ");
	}
}